<style>
.table > tbody > tr > td,td {padding:5px 10px;vertical-align: middle;}
.p-list td{line-height:40px !important;}
.cart-num-input{text-align: center;}
.input-group .form-control{padding:6px;}
</style>
<?php $all_virtual = true; foreach($Carts as $cart) { if(!$cart['Cart']['is_virtual']){$all_virtual=false;break;}  } ?>

<script>
var setAmount={
		min:1,
		max:9999,
		reg:function(x){
			return new RegExp("^[1-9]\\d*$").test(x);
		},
		amount:function(obj,mode){
			var x=$(obj).val();
			if (this.reg(x)){
				if (mode){
					x++;
				}else{
					x--;
				}
			}else{
				alert("请输入正确的数量！");
				$(obj).val(1);
				$(obj).focus();
			}			
			return x;
		},
		reduce:function(obj){
			var x=this.amount(obj,false);
			if (x>=this.min){
				$(obj).val(x);
			}else{
				alert("商品数量最少为"+this.min);
				$(obj).val(this.min);
				$(obj).focus();
			}
		},
		add:function(obj){
			var x=this.amount(obj,true);
			if (x<=this.max){
				$(obj).val(x);
			}else{
				alert("商品数量最多为"+this.max);
				$(obj).val(this.max);
				$(obj).focus();
			}
		},
		modify:function(obj){
			var x=$(obj).val();
			if (x<this.min||x>this.max||!this.reg(x)){
				alert("请输入正确的数量！");
				$(obj).val(this.min);
				$(obj).focus();
			}
		}
}
var last_hash = randomString(10);
/* 设置一个hash值校验，防止联系多次点击时，返回的先后顺序不对覆盖成过期数据了 */
var refreshCartContainer = function(request,moreags){
	if(request.hash == last_hash) {
		var html = '<div>' + request.carts_html + '</div>';
		var newhtml = $(html).find('#cart-list-container').html();
		$('#cart-list-container').html(newhtml);
	}
	else{
		// hash 校验数据不对的直接抛弃
	}
}

function deleteCartItem(id){
	last_hash = randomString(10);
	var url=BASEURL+'/carts/delete/'+id+'?hash='+last_hash;	
	// var postdata = {'data[Cart][num]':num,'data[Cart][product_id]':id};
	if(!sso.check_userlogin({"callback":deleteCartItem,"callback_args":arguments}))
		return false;
	
	ajaxAction(url,null,null,refreshCartContainer);
	return false;
}

function submitOrder(form){
	{{if !$all_virtual}}
	if($('input[name="data[Order][consignee_id]"]:checked').size() == 0){
		showErrorMessage("{{__('Please choose or add a new address at first')}}");
		return false;
	}
	{{/if}}
	return true;
}
</script>

<ol class="breadcrumb">
		  <li><a href="/users/index"><i class="fa fa-home"></i>&nbsp;&nbsp;{{__('Personal Center')}}</a></li>
		  <li><a href="/orders/mine">{{__('My Orders')}}</a></li>
		  <li class="active">订单信息</li>
		</ol>           
       <hr>
       

{{$this->Form->create('Order',array(
	'class'=>'form-horizontal',
	'role'=>"form",
	'url'=> $this->Html->url('/orders/edit/'.$order_id),
))}}
	<div class="orderinfo">
		<div class="mt10">
			{{if $orderinfo['Order']['status'] == 1}}
				<div class="alert alert-success">订单已支付</div>
			{{elseif $orderinfo['Order']['status'] == -1}}
				<div class="alert alert-success">订单已取消</div>
			{{/if}}
		</div>
		{{if !$all_virtual}}{{/if}}
		
		<div id="part_payTypeAndShipType"><!-- template orders/info_shiptype--></div>
		
		<!-- 
		{{if $order_id}}
			<div id="part_invoice">--template orders/order_invoice</div>
		{{else}}
			<div id="part_invoice">--template orders/edit_invoice</div>
		{{/if}}
		 -->
		<div class="ui-portlet-header">
			      <span class="title">订单信息</span> 
		</div>
			<p><br/></p>	
		 {{loop $order['Order']['serialize_info'] $k $v}}
		 	<p style"margin-bottom:15px;">{{$k}} : {{$v}}</p> 
		 {{/loop}}

		 <p> 备注：{{nl2br($order['Order']['remark'])}}</p>
		 <hr/>

		<div id="cart-list-container">
		<div class="ui-portlet-header">
			      <span class="title">商品清单</span> 
		</div>
			<p><br/></p>		

			<?php $origin_total = 0; ?>
		<div class="p-list">
			
			

			{{if $is_mobile}}
				{{loop $Carts $cart}}
				<div class="clearfix">
					<p><strong>
					{{if $cart['Cart']['product_id']}}
						<a href="{{Router::url('/'.Inflector::tableize($cart['Cart']['product_model']).'/view/'.$cart['Cart']['product_id'])}}" target="_blank">{{$cart['Cart']['name']}}</a>
					{{else}}
						{{$cart['Cart']['name']}}
					{{/if}}</strong></p>
					<p>{{loop $cart['Cart']['serialize_info'] $k $v}}
						<?php if(empty($v) || $k=='座位号') continue; ?>
					<span style"margin-right:15px;">{{$k}} : {{$v}}</span> 
					{{/loop}}</p>

					{{if $order['Order']['model']=='ReserveTrain' && $cart['Cart']['serialize_info']['身份证']}}
					<p> 座位号:<input type="text" style="width: 120px;display: inline-block;" placeholder="" class="form-control" name="data[Cart][{{$cart['Cart']['id']}}][serialize_info][座位号]" value="{{$cart['Cart']['serialize_info']['座位号']}}" /></p>
					{{/if}}

					<div>
						价格：<input style="width: 80px;display: inline-block;    padding: 5px 10px;" class="form-control" type="text" name="data[Cart][{{$cart['Cart']['id']}}][price]" value="{{$cart['Cart']['price']}}">
					
							数量：<div style="display:inline-block;vertical-align: middle;"><div class="input-group" style="width:105px;">
							<span class="reduce input-group-addon" onclick="setAmount.reduce('#pamount-{{$cart['Cart']['id']}}')">-</span>
							<input type="number" size="4" id="pamount-{{$cart['Cart']['id']}}" data-id="{{$cart['Cart']['id']}}" data-price="{{$cart['Cart']['price']}}" class="form-control cart-num-input" name="data[Cart][{{$cart['Cart']['id']}}][num]" value="{{$cart['Cart']['num']}}" />
							<span class="add input-group-addon" onclick="setAmount.add('#pamount-{{$cart['Cart']['id']}}')">+</span>
							</div></div>
					</div>
				</div>
				<hr/>
				{{/loop}}

			{{else}}
				<table  class="table">
				<tr><th width="50%">商品名称</th>
{{if $order['Order']['model']=='ReserveTrain'}}
<th>座位号</th>
{{/if}}
					<th>购买价格</th><th>商品数量</th></tr>
				<tbody>
				{{loop $Carts $cart}}
					<tr><td>
					{{if $cart['Cart']['product_id']}}
						<a href="{{Router::url('/'.Inflector::tableize($cart['Cart']['product_model']).'/view/'.$cart['Cart']['product_id'])}}" target="_blank">{{$cart['Cart']['name']}}</a>
					{{else}}
						{{$cart['Cart']['name']}}
					{{/if}}
					<p>{{loop $cart['Cart']['serialize_info'] $k $v}}
						<?php if(empty($v) || $k=='座位号') continue; ?>
					<span style"margin-right:15px;">{{$k}} : {{$v}}</span> 
					{{/loop}}</p>
				</td>
				{{if $order['Order']['model']=='ReserveTrain'}}
					<td> 
						{{if $cart['Cart']['serialize_info']['身份证']}}
						<input type="text" style="width: 120px;" class="form-control" name="data[Cart][{{$cart['Cart']['id']}}][serialize_info][座位号]" value="{{$cart['Cart']['serialize_info']['座位号']}}" />{{/if}}</td>
					{{/if}}
				<td>
					<input style="width: 80px;" class="form-control" type="text" name="data[Cart][{{$cart['Cart']['id']}}][price]" value="{{$cart['Cart']['price']}}">
				</td>
				<td>

	<div class="input-group" style="float:left;width:135px;">
	<span class="reduce input-group-addon" onclick="setAmount.reduce('#pamount-{{$cart['Cart']['id']}}')">-</span>
	<input type="number" size="4" id="pamount-{{$cart['Cart']['id']}}" data-id="{{$cart['Cart']['id']}}" data-price="{{$cart['Cart']['price']}}" class="form-control cart-num-input" name="data[Cart][{{$cart['Cart']['id']}}][num]" value="{{$cart['Cart']['num']}}" />
	<span class="add input-group-addon" onclick="setAmount.add('#pamount-{{$cart['Cart']['id']}}')">+</span>
	</div>
				
				</td>				
				</tr>
				{{/loop}}
				</tbody>
				</table>
			{{/if}}
			
		</div>		

		
		<div class="text-right form-inline clearfix">
			
			<p class="mb10">快递费用：<input style="width:80px;" type="text" name="data[Order][ship_fee]" maxlength="200" value="{{$order['Order']['ship_fee']}}" class="form-control" style="width:300px;" id="order_remark"></p>		
		
			<p><input class="btn btn-primary" type="submit" value="确认" ></p>
		</div>
		</div>
		
	</div>
</form>